package com.ruoyi.fetvApi.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.fetvApi.domain.FetvInformationApi;
import com.ruoyi.fetvApi.service.IFetvInformationApiService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资讯Controller
 * 
 * @author zhengmingjie
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/index/fetv/information")
@CrossOrigin
public class FetvInformationApiController extends BaseController
{
    @Resource
    private IFetvInformationApiService fetvInformationService;

    /**
     * 查询资讯列表
     * @param fetvInformationApi
     * @return
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(FetvInformationApi fetvInformationApi)
    {
        startPage();
        List<FetvInformationApi> list = fetvInformationService
                .selectFetvInformationList(fetvInformationApi);
        return getDataTable(list);
    }

    /**
     * 根据新闻ID查询新闻详情
     * @param informationId
     * @return
     */
    @Anonymous
    @GetMapping
    public AjaxResult getInformationById(@RequestParam Integer informationId)
    {
        //增加资讯浏览量
        fetvInformationService.addBrowseNum(informationId);
        return success(fetvInformationService
                .getInformationById(informationId));
    }

    /**
     * 一次性返回30条最新发布的新闻 包含标题、tid
     */
    @Anonymous
    @GetMapping(value = "/thirtyInformation")
    public TableDataInfo getInformationByThirty(FetvInformationApi fetvInformationApi)
    {

        List<FetvInformationApi> fetvInformationApis = fetvInformationService
                .selectFetvInformationApiByThirtyInformation(fetvInformationApi);

        return getDataTable(fetvInformationApis);

    }

    /**
     * 最新新闻 返回今天发布的新闻对象包含标题和tid 最少为0 最多为10条
     */
    @Anonymous
    @GetMapping(value = "/TodayInformation")
    public TableDataInfo getInformationByToday(FetvInformationApi fetvInformationApi)
    {
        List<FetvInformationApi> fetvInformationApis = fetvInformationService
                .selectFetvInformationApiByTodayInformation(fetvInformationApi);

        return getDataTable(fetvInformationApis);

    }

    /**
     * 要点新闻 返回最近发布的新闻对象 包含新闻标题 新闻id 最少为0 最多为10条
     */
    @Anonymous
    @GetMapping(value = "/RecentInformation")
    public TableDataInfo getInformationByRecent(FetvInformationApi fetvInformationApi)
    {
        List<FetvInformationApi> fetvInformationApis = fetvInformationService
                .selectFetvInformationApiByRecentInformation(fetvInformationApi);

        return getDataTable(fetvInformationApis);

    }

    /**
     *
     * 1.点击导航栏 返回对应分类的10条新闻 每个新闻包含标题、时间、tid 参数：
     * name=‘福建教育报道‘
     */
    @Anonymous
    @GetMapping(value = "/NavInformation")
    public TableDataInfo getInformationByNav(FetvInformationApi fetvInformationApi)
    {
        List<FetvInformationApi> fetvInformationApis = fetvInformationService
                .selectFetvInformationApiByRecentInformation(fetvInformationApi);

        return getDataTable(fetvInformationApis);

    }
    /**
     * 根据微视频的id，查询微视频详情
     */
    @Anonymous
    @GetMapping(value = "/getVideo")
    public AjaxResult getVideoById(@RequestParam Integer informationId)
    {
        //增加资讯浏览量
        fetvInformationService.addBrowseNum(informationId);
        return success(fetvInformationService
                .getVideoById(informationId));
    }

    /**
     * 根据标题模糊搜索新闻
     * @param title
     * @return
     */
    @Anonymous
    @GetMapping("/getSearchTitle")
    public AjaxResult getSearchTitle(@RequestParam String title)
    {
        if (title == null || "".equals(title)) {
            return error("请输入搜索内容");
        }
        return success(fetvInformationService
                .selectFetvInformationSearch(title));
    }
    /**
     * 十条推荐搜索
     * @param
     * @return
     */
    @Anonymous
    @GetMapping("/Search")
    public AjaxResult tenSearch(FetvInformationApi fetvInformationApi)
    {
        return success(fetvInformationService
                .selectFetvInformationSearchRecommend(fetvInformationApi));
    }



}
